package com.example.webmodule.controller;

import com.example.webmodule.entity.ServiceInfo;
import com.example.webmodule.strategy.RegistrySelectStrategy;
import com.example.webmodule.strategy.RegistryStrategyFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/web/eureka")
public class EurekaController {

    @Autowired
    private RegistryStrategyFactory registryStrategyFactory;

    @GetMapping("/getEurekaData")
    public List<ServiceInfo> getEurekaData() throws Exception {
        RegistrySelectStrategy registrySelectStrategy = registryStrategyFactory.getStrategy();
        String serviceId = registrySelectStrategy.getServices().stream().findAny().get();
        List<ServiceInfo> list = registrySelectStrategy.getServiceInstances(serviceId);
        return list;
    }
}
